package com.cy.teducommunitys.com.cy.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cy.teducommunitys.com.common.vo.JsonResult;
import com.cy.teducommunitys.com.common.vo.RoleMenuVo;
import com.cy.teducommunitys.com.cy.entity.Role;
import com.cy.teducommunitys.com.cy.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 用户角色 前端控制器
 * </p>
 *
 * @author mdzz
 * @since 2019-07-19
 */
@RestController
@RequestMapping("/cy/role/")
public class RoleController extends BaseController<Role>{
    private IRoleService svc;
    @Autowired
    public RoleController(IRoleService svc){
        super(svc);
        this.svc = svc;
    }

    @RequestMapping("findAllObjects")
    public JsonResult findAllObjects(Page page, String name){
        HashMap<String,Object> map = new HashMap<>();
        map.put("name",name);
        return super.findAllObjects(page,map);
    }

    @RequestMapping("saveObject")
    public JsonResult saveObject(Role entity,Integer[] menuIds){
        int rows = svc.saveObject(entity,menuIds);
        return  new JsonResult("保存成功");
    }

    @RequestMapping("deleteObject")
    public JsonResult deleteObject(Integer id){
        return super.deleteObject(id);
    }

    @RequestMapping("findObjectById")
    public JsonResult findObjectByRoleId(Integer id){
        RoleMenuVo roleMenuVo = svc.findObjectByRoleId(id);
        return new JsonResult(roleMenuVo);
    }
    /**
     * 用于查询角色列表
     * */
    @RequestMapping("doFindZTreeNodes")
    public JsonResult doFindZTreeNodes(){
        List<Role> list = svc.list();
        return new JsonResult(list);
    }
}

